﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
@section header{

}
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li>
                        表名称：<input id="tableName" col="TableName" type="text" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="btn-group-sm" id="toolbar">
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showGenerateForm()"><i class="fa fa-edit"></i> 生成</a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/SystemManage/Database/GetTablePageListJson")';
        $('#gridTable').ysTable({
            url: queryUrl,
            sortName: 'TableName',
            sortOrder: "Asc",
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'TableName', title: '表名称', sortable: true },
                { field: 'TableKeyName', title: '主键名称' },
                { field: 'TableKey', title: '主键字段' },
                { field: 'TableCount', title: '记录数' },
                { field: 'Remark', title: '备注' }
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $("#searchDiv").getWebControls(pagination);
                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function showGenerateForm() {
        var tableName = '';
        var selectedRow = $("#gridTable").bootstrapTable("getSelections");
        if (!ys.checkRowEdit(selectedRow)) {
            return;
        }
        else {
            tableName = selectedRow[0].TableName;
        }

        ys.openDialog({
            title: "生成代码",
            content: '@Url.Content("~/ToolManage/CodeGenerator/CodeGeneratorForm")' + '?tableName=' + tableName,
            width: "1100px",
            height: "600px",
            btn: [],
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }
</script>
